package com.core.nice_view;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.core.R;

/**
 * Created by nice on 16/4/12.
 */
public class ViewJumpItem extends LinearLayout {

    private ImageView idIcon;
    private TextView idTvTitle;
    private TextView idTvTip;
    private OnClickJumpViewListener listener;

    public interface OnClickJumpViewListener {
        public void onClickJump();
    }

    public ViewJumpItem(Context context) {
        super(context);
        initView(context);
    }

    public ViewJumpItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    private void initView(Context context) {
        LayoutInflater inflater = LayoutInflater.from(context);
        inflater.inflate(R.layout.setting_me_item, this, true);
        idIcon = (ImageView) findViewById(R.id.id_icon);
        idTvTitle = (TextView) findViewById(R.id.id_tv_title);
        idTvTip = (TextView) findViewById(R.id.id_tv_tip);
        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onClickJump();
                }
            }
        });
    }

    public void setData(ViewJumpBean model, OnClickJumpViewListener listener) {
        if (model == null) {
            return;
        }
        this.listener = listener;
        if(model.getIcon_id() != 0){
            idIcon.setVisibility(VISIBLE);
            idIcon.setBackgroundResource(model.getIcon_id());
        }
        idTvTitle.setText(model.getName());
        if (!TextUtils.isEmpty(model.getPrompt())) {
            idTvTip.setText(model.getPrompt());
        } else {
            idTvTip.setText("");
        }
    }
}
